package main;

import java.io.IOException;
import java.util.HashMap;

import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.Sound;
import org.newdawn.slick.geom.Vector2f;
import state.*;

import button.*;

import constans.Flag;
import constans.Globals;
import constans.ResourceManager;

public class Game extends BasicGame {

	//stany gry
	private static State state;
	private static HashMap<Integer, State> states = new HashMap<Integer, State>();
   
    public Game(String title) {
		super(title);

    }
	public void render(GameContainer container, Graphics g) throws SlickException {	
		state.render(container, g);
	}
	public void init(GameContainer container) throws SlickException {
		//ladowanie zasobow
		if (!Globals.RESOURCES_INITIATED)
		{
			try {
				ResourceManager.loadResources("data/resources.xml");
			} catch (IOException e) {
				e.printStackTrace();
			}
			Globals.RESOURCES_INITIATED = true;
		}
		//---------------------------------------
		
		//kursor
		states.put(Flag.MENU_STATE, new MenuState());
		states.put(Flag.SINGLEPLAYER_STATE, new SinglePlayerState());
		states.put(Flag.MULTIPLAYER_STATE, new MultiplayerState());
		states.put(Flag.AUTHOR_STATE, new AuthorState());
		states.put(Flag.GAMEPLAY_STATE, new GameplayState());
		//poczatek gry
		state = states.get(Flag.MENU_STATE);
	}
	public void update(GameContainer container, int delta)
			throws SlickException {
		
		Input input = container.getInput();
		
		state.update(container, delta);
		
	}
	public static void setState(int id)
	{
		if(id == Flag.QUIT_STATE) System.exit(0);
		state = states.get(id);	
	}
	


}